﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace ZoDream.Shared.OS.WinApi
{
    public static class HotKeysNativeMethods
    {
        /// <summary>
        /// 热键消息，在用户键入被RegisterHotKey函数注册的热键时发送
        /// </summary>
        public const int WM_HOTKEY = 0x312;
        /// <summary>
        ///     Defines a system-wide hot key.
        /// </summary>
        /// <param name="hwnd">
        ///     A handle to the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL,
        ///     WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.
        /// </param>
        /// <param name="id">
        ///     The identifier of the hot key. If the hWnd parameter is NULL, then the hot key is associated with the current
        ///     thread rather than with a particular window. If a hot key already exists with the same hWnd and id parameters, see
        ///     Remarks for the action taken.
        /// </param>
        /// <param name="fsModifiers">
        ///     The keys that must be pressed in combination with the key specified by the uVirtKey parameter in order to generate
        ///     the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values.
        /// </param>
        /// <param name="vk">
        ///     The virtual-key code of the hot key. See Virtual Key Codes.
        /// </param>
        /// <returns>
        ///     If the function succeeds, the return value is nonzero.
        ///     If the function fails, the return value is zero. To get extended error information, call GetLastError.
        /// </returns>
        [DllImport("user32.dll")]
        public static extern bool RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk);

        /// <summary>
        ///     Frees a hot key previously registered by the calling thread.
        /// </summary>
        /// <param name="hwnd">
        ///     A handle to the window associated with the hot key to be freed. This parameter should be NULL if the hot key is not
        ///     associated with a window.
        /// </param>
        /// <param name="id">
        ///     The identifier of the hot key to be freed.
        /// </param>
        /// <returns>
        ///     If the function succeeds, the return value is nonzero.
        ///     If the function fails, the return value is zero. To get extended error information, call GetLastError.
        /// </returns>
        [DllImport("user32.dll")]
        public static extern bool UnregisterHotKey(IntPtr hwnd, int id);
        /// <summary>
        /// 向原子表中添加全局原子
        /// </summary>
        /// <param name="lpString"></param>
        /// <returns></returns>
        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern short GlobalAddAtom(string lpString);
        /// <summary>
        /// 在表中搜索全局原子
        /// </summary>
        /// <param name="lpString"></param>
        /// <returns></returns>
        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern short GlobalFindAtom(string lpString);
        /// <summary>
        /// 在表中删除全局原子
        /// </summary>
        /// <param name="nAtom"></param>
        /// <returns></returns>
        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern short GlobalDeleteAtom(string nAtom);
    }
}
